package com.example.demo.controller;

import com.example.demo.Mappers.PatientInfoMapper;
import com.example.demo.beans.*;
import com.example.demo.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by Administrator on 2018/4/2.
 */

@RestController
public class PublicController {
    /**
     * 1.1网络通讯测试
     * @param request
     * @return
     */
    @Autowired
    private PatientInfoMapper patientInfoMapper;

    @ResponseBody
    @RequestMapping(value = "HisTest", produces = {"application/xml"})
    public TestResponse HisTest(@RequestBody(required = false) HisTestRequest request) {
        if (request != null) {
            System.out.println(request.getUserID());
        }
        return new TestResponse("0", "succeed", DateUtils.getCurDataString());
    }

    /**
     * 获取病人信息
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "GetPatientInfo", produces = {"application/xml"})
    public PatientInfo GetPatientInfo(@RequestBody PatientRequest request) {

        System.out.print(request.getCardNo());
      //  PatientInfo patientInfo= new PatientInfo();
      //  PatientInfo patientInfo = patientInfoMapper.selectpatientbyid(request.getCardNo());
        //System.out.print(patientInfo);
        //  System.out.print(patientInfo.getName());

        if (request != null) {
            PatientInfo     patientInfo =         patientInfoMapper.selectpatientbyid(request.getCardNo());
            if (patientInfo != null) {
                return patientInfo;
            } else {
                PatientInfo patientInfo1 = new PatientInfo();
                patientInfo1.setResultcode("1");
                patientInfo1.setResultmsg("该医疗卡没有注册在医院信息系统中，请注册！");
                return patientInfo1;
            }

        } else {
            PatientInfo p = new PatientInfo();
            p.setResultcode("2");
            p.setResultmsg("请求为空，请查证！");
            return p;
        }

    }

    /**
     *
     * @param request
     */

    @ResponseBody
    @RequestMapping(value = "CheckIDCard", produces = {"application/xml"})
    public CheckIDCardResponse checkIDCardResponse(@RequestBody CheckIDCardRequest request){
if(request!=null){
   CheckIDCardResponse responses=patientInfoMapper.selectcheckidcardbyID(request.getiDCardNo());
    if(responses!=null){return responses;
    }
    else {
        CheckIDCardResponse response=new CheckIDCardResponse();
        response.setResultCode("0");
        response.setResultMsg("数据中心没有查询到该身份证绑定的医疗卡，请查证！");
        response.setStatus("0");
        return response;
    }
}
return null;
    }
}
